﻿using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using DomainModel;

namespace DataAccess
{
    class PostConfiguration : EntityTypeConfiguration<Post>
    {
        public PostConfiguration()
        {
            Property(p => p.Id).IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            HasKey(p => p.Id);
            Property(p => p.RowId).IsConcurrencyToken();
            HasOptional(p => p.Poll).WithRequired(p => p.Post);
            HasRequired(p => p.Author).WithMany().WillCascadeOnDelete(false);
            HasOptional(p => p.ModifiedBy);
            HasRequired(p => p.Thread).WithMany(p => p.Posts).HasForeignKey(p => p.ThreadId);
        }
    }
}
